package com.tentact.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.stereotype.Service;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.tentact.service.DepartmentService;
import com.tentact.vo.Department;

@Controller
public class DepartmentController {
	@Autowired
	private DepartmentService service;
	//查询全部
	@RequestMapping("/selectAllDepts")
	public String selectAll(Model model) {
		List<Department>departments = service.selectAll();
		model.addAttribute("depts", departments);
		return "departments";
	}
	//添加部门
	@RequestMapping("/insertDept")
	public String insert(Department department) {
		service.insertSelective(department);
		return "redirect:selectAllDepts";
	}
	//修改部门
	@RequestMapping("/updateDept")
	public String update(Department department) {
		System.out.println(department.getDepartmentid()+"\t"+department.getDepartmentname());
		int result=service.update(department);
		System.out.println(result);
		return "redirect:selectAllDepts";
	}
	//删除部门
	@RequestMapping("/deleteDept")
	public String delete(Department department) {
		service.delete(department);
		return "redirect:selectAllDepts";
	}

}
